package com.hd123.data.check.config;

import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * description:
 * 自定义填充公共字段
 *
 * Date: 2017/12/25
 * Time: 16:21
 *
 * @author zhangxin
 */
@Component(value = MyMetaObjectHandler.META_OBJECT_HANDLER_BEAN_NAME)
public class MyMetaObjectHandler extends MetaObjectHandler{

    public final static String META_OBJECT_HANDLER_BEAN_NAME = "myMetaObjectHandler";

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Override
    public void insertFill(MetaObject metaObject) {

        // 测试下划线
        //mybatis-plus版本2.0.9+
        Object testType = getFieldValByName("uuid", metaObject);
        log.info("uuid = " + testType);
        if (testType == null) {
            setFieldValByName("uuid", 3, metaObject);
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {

    }
}
